package io.renren.modules.jxgk.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.common.utils.R;
import io.renren.common.utils.ShiroUtils;
import io.renren.modules.jxgk.entity.TeacherCourseContentEntity;
import io.renren.modules.jxgk.service.TeacherCourseContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("TeacherCourseContent/")
public class TeacherCourseContentController {

    @Autowired
    TeacherCourseContentService teacherCourseContentService;





    @RequestMapping("Select")
    public R list(@RequestParam Map<String, Object> params){
        //查询列表数据
        int total;
        PageUtils pageUtil = null;
        //获取当前用户id
        String id= ShiroUtils.getUserEntity().getUsername();
        Query query = new Query(params);
        String courseName= (String) params.get("courseName");
        if(courseName==null||courseName.equals(""))
        {
            
        }else {
            List<TeacherCourseContentEntity> cse = teacherCourseContentService.queryList(query, id);
             total = teacherCourseContentService.queryTotal(query, id);

             pageUtil = new PageUtils(cse, total, query.getLimit(), query.getPage());
        }
        return R.ok().put("page", pageUtil);
    }
    @RequestMapping("/Info/{index}")
    public R info(@PathVariable("index") String index){
        TeacherCourseContentEntity cse = teacherCourseContentService.queryObject(index);
        int n=0;
        return R.ok().put("TeacherCourseContent", cse);
    }

    @RequestMapping("/Update")
    public R update(@RequestBody TeacherCourseContentEntity cse){
        teacherCourseContentService.update(cse);
        return R.ok();
    }
    @RequestMapping("/UpdateAll")
    public R updateAll(@RequestBody TeacherCourseContentEntity cse){
        teacherCourseContentService.updateAll(cse);
        return R.ok();
    }
    @RequestMapping("/Count/{courseName}")
    public R Count(@RequestParam Map<String, Object> params,@PathVariable("courseName") String courseName){
        //查询列表数据

        //获取当前用户id
        Map<String, Object> param=new HashMap<String, Object>() ;
        String id= ShiroUtils.getUserEntity().getUsername();
        double percentage = teacherCourseContentService.queryProcedure(id,courseName);
        return R.ok().put("teacherCount", percentage*100);
    }
    @RequestMapping("/selectCourseName")
    public R nameList(){
        //查询列表数据
        String id= ShiroUtils.getUserEntity().getUsername();
        List<String> cse = teacherCourseContentService.queryCourseName(id);
        return R.ok().put("list", cse);
    }
}